package com.zpark.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.zpark.i_feign.IUserFeign;
import com.zpark.pojo.User;
import com.zpark.util.ResultJsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @PackageName: com.zpark.controller
 * @ClassName: ClientController
 * @Description:
 * @author: RZS
 * @date: 2024/4/18  17:42
 */
@RestController
@RequestMapping("/client")
public class ClientController {

    @Autowired
    private IUserFeign userFeign;

    @GetMapping("/all")
    public ResultJsonUtil<List<User>> getAll(){
        return userFeign.getAll();
    }

    @GetMapping("/test")
    @HystrixCommand(fallbackMethod = "fallTest")
    public ResultJsonUtil<Void> test(){
        return userFeign.test();
    }

    private ResultJsonUtil<Void> fallTest(){
        return new ResultJsonUtil<>(5000, "未知异常", null);
    }
}
